package com.outsider.util.baiduMap;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.kit.PropKit;
import com.outsider.util.OkHttp3;
import com.outsider.weixin.controller.WeixinConfig;


/**
 * 封装 access_token
 */
public class BaiduMapApi {
    private static String ak;
    private static OkHttp3 httpUtil=OkHttp3.getInstance();
    static{
		ak=PropKit.get("ak");
    }
    private static final String GeocodingUrl="http://api.map.baidu.com/geocoder/v2/?";
    public static Address getAddress(String longitude, String latitude){
    	String json=httpUtil.get(GeocodingUrl+"ak="+ak+"&output=json&location="+latitude+","+longitude);
    	JSONObject temp=JSONObject.parseObject(json);
    	Address address=new Address();
    	address.setCountry(temp.getJSONObject("result").getJSONObject("addressComponent").get("country").toString());
    	address.setProvince(temp.getJSONObject("result").getJSONObject("addressComponent").get("province").toString());
    	address.setCity(temp.getJSONObject("result").getJSONObject("addressComponent").get("city").toString());
    	address.setDistrict(temp.getJSONObject("result").getJSONObject("addressComponent").get("district").toString());
    	
    	return address;
    }
}
